#include "TheWorld.h"
#include "World\WorldSpace.h"
#include <filesystem>
#include <iostream>

using namespace World;

TheWorld::TheWorld()
{
}

TheWorld::~TheWorld()
{
}

void TheWorld::generate(const std::string &path)
{
	cfg_parser = std::make_shared<TCODParser>();

	if(std::tr2::sys::is_directory(std::tr2::sys::path(path)))
    {
		for(std::tr2::sys::directory_iterator itr(path); itr!=std::tr2::sys::directory_iterator(); ++itr)
		{
			auto filename = itr->path().filename();
			if(filename.find(".cfg") != std::string::npos)
			{
				std::cout << "- " << filename << ": ";
			
				auto space = std::make_shared<WorldSpace>();
				worldSpaces.push_back(space);
				space->generate(cfg_parser, path+"\\"+filename);
			}
		}
	}
}

void TheWorld::render()
{
	getRoot()->render();
}
